let obj = { name: 'henry', age: 22 }

let obj2 = Object.assign(obj, { weight: '50kg' }, { hobby: [] })

console.log(obj2) //=> {name: "henry", age: 22, weight: "50kg",bobby:[]}

console.log('===')

let obj0 = { name: 'henry', age: 22 }
// 缺陷：只支持合并一个对象
Object.assign = (obj, obj2) => {
  if (obj == null) throw new Error('TypeError ...')
  let newObj = {}
  for (let key in obj) newObj[key] = obj[key]
  for (let key in obj2) newObj[key] = obj2[key]
  return newObj
}
let obj3 = Object.assign(obj0, { weight: '50kg' }, { hobby: [] })

console.log(obj3) //=> {name: "henry", age: 22, weight: "50kg"}
